#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)
const int N = 100010;
int n, sz[N], fa[N], minn = 1e9, cent1, cent2;
vector<int> g[N];
int S;
void dfs(int x, int f) {
  fa[x] = f, sz[x] = 1;
  int mx = 0;
  for (int y : g[x]) {
    if (y == f) continue;
    dfs(y, x);
    sz[x] += sz[y];
    mx = max(mx, sz[y]);
  }
  mx = max(mx, n - sz[x]);
  if (mx < minn)
    minn = mx, cent1 = x, cent2 = 0;
  else if (mx == minn)
    cent2 = x;
}
void dfs2(int x, int f) {
  if (g[x].size() == 1) {
    S = x;
    return;
  }
  for (int y : g[x]) {
    if (y == f) continue;
    dfs2(y, x);
  }
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    cent1 = cent2 = 0, minn = 1e9;
    rep(i, 1, n + 1) g[i].clear(), fa[i] = 0;
    rep(i, 1, n) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0);
    if (!cent2) {
      printf("1 %d\n1 %d\n", g[1][0], g[1][0]);
      continue;
    }
    if (fa[cent1] != cent2) swap(cent1, cent2);
    dfs2(cent1, cent2);
    printf("%d %d\n%d %d\n", S, fa[S], S, cent2);
  }
}
